﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyBanHang.Lib;
using QuanLyBanHang.GUI;

namespace QuanLyBanHang.GUI
{
    public partial class frmChangePass : Form
    {
        #region "Variables"
        public string _userName;
        public string _userPass;
        public string _NewPass;
        private DataTable dtbUser;
        #endregion
        public frmChangePass(string _strname)
        {
            InitializeComponent();
            _userName = _strname;
        }

        private void frmChangePass_Load(object sender, EventArgs e)
        {
            dtbUser = KetNoi.GetTable("select * from tblNhanVien where MaNhanVien = '" + _userName + "'");
            _userPass = dtbUser.Rows[0]["MatKhau"].ToString().Trim();
            txtUserName.Text = _userName;
        }

        private void btnDongy_Click(object sender, EventArgs e)
        {
            if ((txtOldPass.Text != null) && (txtOldPass.Text == _userPass))
            {
                if (txtNewPass.Text != null)
                    try
                    {
                     int i =   KetNoi.ExcuteSQL("update tblNhanVien set MatKhau = '" + txtNewPass.Text + "' where MaUser = '" + txtUserName.Text + "'  ");
                        if (i>0)
                        {
                            MessageBox.Show("Cập nhật mật khẩu thành công");
                        }
                    }
                    catch (System.Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    
                else
                    MessageBox.Show("Chua nhap passworld");
            }
            else
                MessageBox.Show("Mat khau cu khong dung");
        }
    }
}
